package learning.spring.helloworld.listener;

import learning.spring.helloworld.custom.CustomEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 通过 @EventListener 注解监听 ApplicationContext 的关闭事件
 */
@Component
public class ContextClosedEventAnnotationListener {

    @EventListener
    @Order(1)// 与 ContextClosedEventListener 中的order进行排序
    public void onEvent(ContextClosedEvent event) {// 监听容器关闭内置事件
        System.out.println("[@EventListener] ApplicationContext closed ");
    }

    @EventListener
    public void onEvent2(CustomEvent customEvent) {// 同一类中可以再监听自定义事件
        System.out.println("[@EventListener] customEvent ");
    }

}
